<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
		<title>确认支付</title>
		<%@include file="../common/common.jsp" %>
		<%
		    String basePath = request.getScheme() + "://"+ request.getServerName() + request.getContextPath()+ "/";
		%>
	    <script	type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
		<script type="text/javascript">	
		$(function(){  
	    	 history.replaceState({}, "订单详情", rootPath + '/order/orderData?orderId='+ $("#orderId").val());//将该页面的url替换为订单详情页面,而不刷新页面  
	         //window.history.pushState({}, "", rootPath + '/order/orderData?orderId='+ $("#orderId").val());  //在历史页面中新增一个订单详情页面，而不刷新
	         window.history.pushState({}, "订单详情", rootPath + '/order/orderData?orderId='+ $("#orderId").val());  //在历史页面中新增一个订单详情页面，而不刷新
	    	 window.addEventListener("popstate", function(e) {  
		         //alert("我监听到了浏览器的返回按钮事件啦");//根据自己的需求实现自己的功能  
		        //alert("上一页："+$("#preHistoryUrl").val());
		         if($("#detailPay").val() =="detailPay"){
		          	  history.back(1);
		         }else{
				      window.location.replace(rootPath+ '/order/orderData?orderId='+ $("#orderId").val()); 
		         }
		        }, true);  
		    });
	       function returnOneOrderPage(){
	    	   if($("#detailPay").val() =="detailPay"){
		          	  history.back(1);
		         }else{
		          	  history.back(1);
			          window.location.replace(rootPath+ '/order/orderData?orderId='+$("#orderId").val());
		         } 
	       }  
		</script>
		
       <%String ref = request.getHeader("REFERER");%>
       
	</head>

	<body>
		<header>
			<nav class="headerTwo">
			<input type="hidden" id="detailPay" value="${detailPay}"/>
			<input type="hidden" id="preHistoryUrl" value="<%=ref%>">
				<img src="${ctx }/image/bg.png" alt="" />
			<%-- 	<a href="javascript:window.location='<%=ref%>'" class="fl"><img src="${ctx }/image/return.png" alt="" /></a>  --%>
				<a href="javascript:returnOneOrderPage()" class="fl"><img src="${ctx }/image/return.png" alt="" /></a> 
				<h2>确认支付</h2>
			</nav>
		</header>
		<div class="pay"></div>
		<ul class="personOrder  clearfix">
			   <li class="personImg fl">
				<img src="${ctx }/image/wx.png" alt=""/>
				<span>微信支付</span>
			   </li>
			   <li class="personOrder_img fr">
					<img src="${ctx }/image/agree1.png" alt=""/>
			   </li>
		</ul>
		<ul class="personOrder clearfix">
			   <li class="personImg fl">
				<img src="${ctx }/image/zfb.png" alt=""/>
				<span>支付宝支付</span>
			   </li>
			   <li class="personOrder_img choose fr">
					<%-- <img src="${ctx }/image/agree.png" alt=""/> --%><sapn class="red">（暂未开通)</sapn>
			   </li>
		</ul>
		
		 <ul class="personOrder mps clearfix">
			   <li class="fl">
			   	<a href="" class="personImg personW">
			   		<img src="${ctx }/image/shortcut.png" alt=""/>
				    <span>畅捷支付</span>
			   	</a>	
			   </li>
			   <li class="fr ">
			   <sapn class="red">（暂未开通)</sapn>
				<%--  <a href="#" >
					<img src="${ctx }/image/center-right.png" alt=""/>
				 </a> --%>
			   </li>
		    </ul>
		    <div class="jiesuan payJ clearfix">
		    <c:if test="${not empty orders  && order == null}">		    
			     <input type="hidden" id ="orderId" value="${orders.get(0).orderId }"/> 
			      <input type="hidden" id="totalAmount" value="${totalAmount }"/>  <!-- 购物车提交与立即购买处提交的付款 -->
		    </c:if> 
		    <c:if test="${order != null }">		    
		       <input type="hidden" id ="orderId" value="${order.orderId }"/>  <!-- 订单列表和订单详情处付款 -->
		       <input type="hidden" id="totalAmount" value="${order.totalAmount }"/> <!-- 购物车提交与立即购买处提交的付款 -->
		    </c:if> 
			    <span>支付:</span>
			    <span class="price"><b>￥</b> 
			         <c:if test="${not empty orders  && order == null }">	
			            ${order.totalAmount } ${totalAmount } <!-- 购物车提交与立即购买处提交的付款 --> 	
				     </c:if>
				     <c:if test="${order != null }">		     
				        ${order.totalAmount } <!-- 订单列表和订单详情处付款 -->
			         </c:if>
		         </span>
			    <a href="javascript:void(0)" class="fr payAction">
				  <p>付款</p>
			    </a>
		</div>
		<script type="text/javascript">

		function pay(){
		    var url="<%=basePath%>wechat/pay?money="+$("#totalAmount").val(); //注意此处的basePath是没有端口号的域名地址。如果包含:80,在提交给微信时有可能会提示 “redirect_uri参数错误” 。
		    //money为订单需要支付的金额
		    //state中存放的为商品订单号
		    var weixinUrl="https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx9741cdd5be95441d&redirect_uri="+encodeURI(url)+"&response_type=code&scope=snsapi_userinfo&state="+ $("#orderId").val() +"#wechat_redirect";
		  	//	    alert("支付页面已关闭");
		    window.location.href=encodeURI(weixinUrl);
		 //   window.location.replace(encodeURI(weixinUrl));
		}
		</script>
		<script type="text/javascript" src="${ctx }/js/public.js"></script>
		<script type="text/javascript" src="${ctx }/js/order/pay.js"></script>
	</body>

</html>